/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include ".\workmethods.h"

//---------------------------------------------------------------------------

WorkMethods::WorkMethods(void)
{
}

WorkMethods::~WorkMethods(void)
{
}

//---------------------------------------------------------------------------

bool WorkMethods::GetMethod(WorkMethod* wmIn, WorkMethodType typeIn)
{
	bool res;

	if(wmIn==NULL) return false;

	wmIn->Initialize();

	res = true;

	wmIn->name        = wd.GetMethodName(typeIn);
	wmIn->description = wd.GetMethodDescription(typeIn);
	wmIn->type        = typeIn;
	wmIn->dataName    = wd.GetMethodParamName(typeIn);

	switch(typeIn){
		case __wmtNone :
		case __wmtArp :
		case __wmtPing :
		case __wmtDns :
		case __wmtIpProtocol :
		case __wmtNetBios :
		case __wmtWakeOnLAN :
		case __wmtWinSnmp :
		case __wmtDhcpDiscov :
		case __wmt6PingBcast :
			wmIn->hasPortMeaning = false;
			break;

		case __wmtSyn :
		case __wmtFin :
		case __wmtNull :
		case __wmtXmas :
		case __wmtAck :
		case __wmtTcpConnect :
		case __wmtUdpSend :
			wmIn->hasPortMeaning = true;
			break;

		default:
			res = false;
			break;
	}

	return res;
}

//---------------------------------------------------------------------------

bool WorkMethods::MethodIsRunningOnPhase(WorkMethodType wmtIn, WorkPhaseType wptIn)
{
	bool res;

	res = false;

	switch(wmtIn){
		case __wmtNone :
			break;

		case __wmtArp:
			break;

		case __wmtPing :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtDns :
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtSyn :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtFin :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtNull :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtXmas :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtAck :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtTcpConnect :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtUdpSend :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtIpProtocol :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtNetBios :
			if(wptIn==__wptDiscovery) res = true;
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtWakeOnLAN :
			if(wptIn==__wptDiscovery) res = true;
			break;

		case __wmtWinSnmp :
			if(wptIn==__wptScan)      res = true;
			break;

		case __wmtDhcpDiscov :
			if(wptIn==__wptDiscovery) res = true;
			break;

		default:
			break;
	}

	return res;
}

//---------------------------------------------------------------------------

CString WorkMethods::GetPhaseName(WorkPhaseType wptIn)
{
	return wd.GetPhaseName(wptIn);
}

//---------------------------------------------------------------------------
